<template>
  <div class="header">
 
    <div class="login-box">
    <h1>用户登录</h1>
    <el-form
      :model="formData"
      label-width="100px"
      :rules="formRules"
      ref="form"
    >
      <el-form-item prop="username">
        <el-input v-model="formData.username"
         prefix-icon="el-icon-user-solid" 
         placeholder="username"></el-input>
      </el-form-item>

      <el-form-item prop="password">
        <el-input  
         v-model="formData.password"
         prefix-icon="el-icon-lock" 
         placeholder="password"
         type="password"
         show-password
         >
         </el-input>
      </el-form-item>
      <el-form-item>
      <el-button class="submit-btn" @click="login" type="primary">登录</el-button>
     </el-form-item>
       
    </el-form>
    </div>
  </div>
</template>

<script>

import axios from 'axios';
export default {
  data() {
    return {
   
      formData: {
    username:'',
    password:''
      },
      formRules: {
        name: [{ required: true, trigger: "blur", message: "用户名不能为空" }],
        password: [
          { required: true, trigger: "blur", message: "密码不能为空" },
        ],
      },
    };
  },

  mounted() {},

  methods: {
    login() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          axios({
            url:'http://192.168.200.251:8888/admin/auth/login',
            method:'post',
            //post请求参数要放到data对象中
            data: {
              ...this.formData
            },
          }).then(res=>{
            console.log(res)
             if(res.data.errno===0){
               this.$notify.success({
                 title:'登录成功'
               })

               setTimeout(()=>{
                  this.$router.push({
                    path:'/main'
                  })
               },500)
             }else{
               this.$notify.error({
                 title:res.data.errmsg
               })
             }
          })
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style scope lang='scss'>
.header {
  background: #2d3a4b;
  position: absolute;
  top:0%;
  left:0%;
  right: 0%;
  bottom: 0%;
  display: flex;
  justify-content: center;
  align-items: center;
 
}
.login-box{
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 520px;
  padding: 35px;
  box-sizing: border-box;

  h1{
    color: #fff;
    font-size: 26px;
  }

  .el-form{
    width: 100%;

    .el-input{
      	
      .el-input__inner{
          height: 50px;
        // hsla() 函数使用色相、饱和度、亮度、透明度来定义颜色。
    	    border: 1px solid hsla(0,0%,100%,.1);
			  	background: rgba(0,0,0,0.1);

      }
    }
  }
  	.submit-btn {
			width: 100%;
}
}
</style>